(function(){"use strict";BX.namespace("BX.Grid");BX.Grid.SettingsWindowColumn=function(t,e){this.node=null;this.label=null;this.checkbox=null;this.editButton=null;this.settings=null;this.parent=null;this.default=null;this.defaultTitle=null;this.state=null;this.lastTitle=null;this.init(t,e)};BX.Grid.SettingsWindowColumn.inited={};BX.Grid.SettingsWindowColumn.prototype={init:function(t,e){this.parent=t;this.node=e;try{this.lastTitle=e.querySelector("label").innerText.trim()}catch(t){}this.updateState();if(!BX.Grid.SettingsWindowColumn.inited[this.getId()]){BX.Grid.SettingsWindowColumn.inited[this.getId()]=true;BX.bind(this.getEditButton(),"click",BX.proxy(this.onEditButtonClick,this));BX.bind(this.getStickyButton(),"click",BX.proxy(this.onStickyButtonClick,this))}},getStickyButton:function(){return this.node.querySelector(".main-grid-settings-window-list-item-sticky-button")},isSticked:function(){return this.node.classList.contains("main-grid-settings-window-list-item-sticked")},onStickyButtonClick:function(){if(this.isSticked()){this.unstick()}else{this.stick()}},stick:function(){this.node.classList.add("main-grid-settings-window-list-item-sticked")},unstick:function(){this.node.classList.remove("main-grid-settings-window-list-item-sticked")},onEditButtonClick:function(t){t.stopPropagation();this.isEditEnabled()?this.disableEdit():this.enableEdit()},setState:function(t){this.state=t},getState:function(){return this.state},updateState:function(){this.setState({selected:this.isSelected(),sticked:this.isSticked(),title:this.getTitle()})},restoreState:function(){var t=this.getState();t.selected?this.select():this.unselect();t.sticked?this.stick():this.unstick();this.setTitle(t.title)},getId:function(){return this.getNode().dataset.name},getTitle:function(){return this.getLabel().innerText},setTitle:function(t){this.getLabel().innerText=!!t&&t!=="undefined"?t:this.getDefaultTitle()},isEdited:function(){return this.getTitle()!==this.getDefaultTitle()},getSettings:function(){if(this.settings===null){var t=this.parent.getParam("DEFAULT_COLUMNS");this.settings=this.getId()in t?t[this.getId()]:{}}return this.settings},isDefault:function(){if(this.default===null){var t=this.getSettings();this.default="default"in t?t.default:false}return this.default},restore:function(){this.isDefault()?this.select():this.unselect();this.setTitle(this.getDefaultTitle());this.node.dataset.stickedDefault==="true"?this.stick():this.unstick();this.disableEdit();this.updateState()},getDefaultTitle:function(){if(this.defaultTitle===null){var t=this.getSettings();this.defaultTitle="name"in t?t.name:this.lastTitle}return this.defaultTitle},getNode:function(){return this.node},getLabel:function(){if(this.label===null){this.label=BX.Grid.Utils.getByTag(this.getNode(),"label",true)}return this.label},getCheckbox:function(){if(this.checkbox===null){this.checkbox=BX.Grid.Utils.getBySelector(this.getNode(),'input[type="checkbox"]',true)}return this.checkbox},getEditButton:function(){if(this.editButton===null){this.editButton=BX.Grid.Utils.getByClass(this.getNode(),this.parent.settings.get("classSettingsWindowColumnEditButton"),true)}return this.editButton},enableEdit:function(){this.getLabel().contentEditable=true;this.getCheckbox().disabled=true;this.adjustCaret()},disableEdit:function(){this.getLabel().contentEditable=false;this.getCheckbox().disabled=false},isEditEnabled:function(){return this.getLabel().isContentEditable},isSelected:function(){return this.getCheckbox().checked},select:function(){this.getCheckbox().checked=true},unselect:function(){this.getCheckbox().checked=false},adjustCaret:function(){var t=document.createRange();var e=window.getSelection();var i=this.getLabel().innerText.length;var s=this.getLabel().childNodes;var n=s[s.length-1];t.setStart(n,i);t.setEnd(n,i);t.collapse(true);e.removeAllRanges();e.addRange(t);BX.fireEvent(this.getNode(),"focus")}}})();